<?php
	/**
	 * @author Matthias Eigner | 0625203
	 */
	class Todo {
		private $id;
		private $title;
		private $description;
		private $target_date;
		private $projected_hours;
		private $creator;
		private $status;
		private $users;
		private $projects;
		private $todo_count;
		
		const STATUS_NEW = 'n';
		const STATUS_ON_SCHEDULE = 'oS';
		const STATUS_BEHIND_SCHEDULE = 'bS';
		const STATUS_WAITING = 'w';
		const STATUS_COMPLETED = 'c';
		
		const GET_STATUS_NORMAL = 10;
		const GET_STATUS_SHORT = 11;
		const GET_STATUS_INTERFACE = 12;

		function __construct($id, $title, $description, $target_date, $projected_hours, $creator, $status){
			$this->id = $id;
			$this->title = $title;
			$this->description = $description;
			$this->target_date = $target_date;
			$this->projected_hours = $projected_hours;
			$this->creator = (is_array($creator))? new UserDescription('', -1, '', '') : $creator;
			$this->status = $status;
			$this->users = array();
			$this->projects = array();
		}
		
		public function addUser($user){
			$this->users[] = $user;
		}
		
		/**
		 * 
		 * adds a project to this todo
		 * @param unknown_type $id
		 * @param unknown_type $title
		 */
		public function addProject($id, $title){
			$this->projects[] = array('id'=>$id, 't'=>$title);
		}
		
		public function setTodoCount($i){
			$this->todo_count = $i;
		}
		
		// Getter
		public function getId(){
			return $this->id;
		}	
		public function getTitle(){
			return $this->title;
		}
		
		public function getDescription() {
			return $this->description;
		}
		
		public function getTargetDate() {
			return date('d.m.Y', $this->target_date);
		}
		
		public function getProjectedHours() {
			return $this->projected_hours;
		}
		
		public function getCreator() {
			return $this->creator;
		}
		
		public function getStatus($short=self::GET_STATUS_NORMAL) {
			return self::getStatusString($this->status, $short);
		}
		
		/**
		 * 
		 * Returns a Server or Filesystem compatible string for a todo status
		 * @param int $status
		 * @param int $short
		 * @return string string of the statuscode
		 */
		public static function getStatusString($status, $short=self::GET_STATUS_NORMAL){
			$short_ar = array(self::STATUS_COMPLETED=>'c',
							self::STATUS_ON_SCHEDULE=>'oS',
							self::STATUS_BEHIND_SCHEDULE=>'bS',
						 	self::STATUS_NEW=>'n',
						 	self::STATUS_WAITING=>'w');
						 	
			$normal_ar = array(self::STATUS_COMPLETED=>'completed',
							self::STATUS_ON_SCHEDULE=>'on schedule',
							self::STATUS_BEHIND_SCHEDULE=>'behind schedule',
						 	self::STATUS_NEW=>'new',
						 	self::STATUS_WAITING=>'waiting');
						 	
			$int_ar = array(self::STATUS_COMPLETED=>'Fertig',
							self::STATUS_ON_SCHEDULE=>'Im Zeitplan',
							self::STATUS_BEHIND_SCHEDULE=>'Hinter dem Zeitplan',
						 	self::STATUS_NEW=>'Neu',
						 	self::STATUS_WAITING=>'Warte');
						 	
			if($short==self::GET_STATUS_SHORT){
				if(in_array($status, array_keys($short_ar))) return $short_ar[$status];
				else return '';
			} else if($short==self::GET_STATUS_NORMAL) {
				if(in_array($status, array_keys($normal_ar))) return $normal_ar[$status];
				else return 'unknown';
			} else if($short==self::GET_STATUS_INTERFACE){
				if(in_array($status, array_keys($int_ar))) return $int_ar[$status];
				else return '';
			} else {return false;exit(0);}
		}
		
		public function getProjects(){
			return $this->projects;
		}
		
		public function getUsers(){
			return $this->users;
		}
		
		public function getTodoCount() {
			return $this->todo_count;
		}
	}
?>